package com.lhy.wcss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhy.wcss.model.domain.BatchSetting;
import com.lhy.wcss.mapper.BatchSettingMapper;
import com.lhy.wcss.model.dto.PageDTO;
import com.lhy.wcss.model.vo.BatchSettingVO;
import com.lhy.wcss.service.BatchSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class BatchSettingServiceImpl extends ServiceImpl<BatchSettingMapper, BatchSetting> implements BatchSettingService {

    @Override
    public Page<BatchSettingVO> getPage(PageDTO pageDTO, BatchSetting batchSetting) {
        Page<BatchSettingVO> page=new Page<>(pageDTO.getPageNum(),pageDTO.getPageSize());
        baseMapper.page(page,batchSetting);
        return page;
    }

    @Override
    public Page<BatchSetting> pageList(PageDTO pageDTO, BatchSetting batchSetting) {
        QueryWrapper<BatchSetting> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(batchSetting.getName())){
            wrapper.like("name",batchSetting.getName());
        }
        if(StringUtils.isNotBlank(batchSetting.getDifficultyLevel())){
            wrapper.like("difficulty_level",batchSetting.getDifficultyLevel());
        }
        if(batchSetting.getActive()!=null){
            wrapper.eq("active",batchSetting.getActive());
        }
        Page<BatchSetting> page = new Page<>(pageDTO.getPageNum(),pageDTO.getPageSize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }

    @Override
    public boolean reset(BatchSetting batchSetting) {
        baseMapper.reset(batchSetting);
        return true;
    }
}
